package com.wangjiacai.utils.utils;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;

import java.lang.reflect.Method;

public class JoinPointUtil {

    public static Method getJoinPointMethod(JoinPoint joinPoint, Class[] parameterType) {
        Signature signature = joinPoint.getSignature();
        String targetClassName = signature.getDeclaringTypeName();
        String methodName = signature.getName();
        try {
            Class targetClass = Class.forName(targetClassName);
            Method method = targetClass.getMethod(methodName, parameterType);
            return method;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Class getJoinPointClass(JoinPoint joinPoint) {
        Signature signature = joinPoint.getSignature();
        String targetClassName = signature.getDeclaringTypeName();
        try {
            Class targetClass = Class.forName(targetClassName);
            return targetClass;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}
